import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;


public class TranditionalTimer {
	
	private static int count = 0;
	
	public static void main(String[] args) {
		//定时器使用：每隔2s执行一次，第一次在1s执行
		/*new Timer().schedule(new TimerTask(){

			@Override
			public void run() {
				System.out.println("bombing...");
			}
			
		}, 1000,2000);*/
		
	
		//定时任务每隔2s,4s,2s,4s,2s......执行
		class MyTimerTask extends TimerTask{
			
			@Override
			public void run() {
				count = (count+1)%2;
				System.out.println("bombing ... ");
				new Timer().schedule(new MyTimerTask(), 2000+2000*count);
			}
		}
		
		new Timer().schedule(new MyTimerTask(), 2000);
		
		while(true){
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(new Date().getSeconds());
		}
		
	}

}
